from datetime import timedelta
from rest_framework import serializers
from clazz.models import Clazz


class ClazzSerializers(serializers.ModelSerializer):
    # 设置计算属性
    graduate_time = serializers.SerializerMethodField(method_name="get_graduate_time")

    def get_graduate_time(self, model):
        return model.start_time + timedelta(days=model.duration * 30)

    # 序列化器
    class Meta:
        model = Clazz
        fields = '__all__'
